<?php
namespace App\Models\WechatMsg;

use App\Models\UserProject;
use App\Models\UserTeam;

class JoinTeam
{
    public  $type;
    public $content;

    public function __construct($type, $content)
    {
        $this->content = $content;
        $this->type = $type;
    }

    public function getOrgWechatConfig()
    {
        $userTeam = UserTeam::where('id', $this->content['user_team_id'])->first();

        $conf['templateId'] = $userTeam->user->org->wechat_message_config['join_team_vol'];

        $options = config('wechat');

        $options['app_id'] = $userTeam->user->org->wechat_app_id;
        $options['secret'] = $userTeam->user->org->wechat_app_secret;

        $conf['options'] = $options;

        $conf['openId'] = $userTeam->user->open_id;

        $conf['url'] = $userTeam->user->org->getBaseUrl().'/team/detail/'.$userTeam->team->id;

        return $conf;
    }


    public function getMessageData()
    {
        $userTeam = UserTeam::where('id', $this->content['user_team_id'])->first();

        $data['first'] = $this->type == 3? "您已成功加入《{$userTeam->team->name}团队》":"您申请加入《{$userTeam->team->name}团队》被拒绝";

        $data['keyword1'] = "《{$userTeam->team->name}团队》加入申请";
        $data['keyword2'] = $this->type == 3? '已加入':'被拒绝';
        $data['remark'] = '点击查看团队详情';

        return $data;
    }
}